import csv
import plotly.express as px
from pathlib import Path
import pandas as pd

# 阅读数据
path = Path('eq_data/world_fires_1_day.csv')
lines = path.read_text().splitlines()
reader = csv.reader(lines)
header_row = next(reader)

# 打印表头及对应索引
for index , columns in enumerate(header_row):
    print(index,columns)

# 收集数据
lons , lats , brightness = [], [] , []
for row in reader:
    lons.append(float(row[1]))
    lats.append(float(row[0]))
    brightness.append(float(row[2]))

# 封装数据
data = pd.DataFrame(
    data = zip(lons,lats,brightness),columns=['经度','纬度','火灾强度']
)

# 根据数据绘制散点图
fig = px.scatter(
    data,
    x='经度',
    y='纬度',
    range_x=[-200,200],
    range_y=[-90,90],
    size='火灾强度',
    size_max=10,
    color = '火灾强度',
    title = 'World Fire 1 Day'
)
fig.write_html('world_fire_1_day.html')
fig.show()